﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using SportsStore.Domain.Abstract;

namespace SportsStore.Domain.Entities
{
    public class Product : IProductRepository
    {
        public int ProductId { get; set; }
        public string Name { get; set; }
        public string Category { get; set; }
        public string Description { get; set; }
        public double Price { get; set; }

        private Random rand = new Random((int) (DateTime.Now.Ticks/999999));

        public IQueryable<Product> Products
        {
            get
            {
                return Enumerable.Range(0, 100).ToList().Select(x => 
                    GenerateDummyProduct()).AsQueryable();
            }
        }

        private Product GenerateDummyProduct()
        {
            var product = new Product
                              {
                                  Name = "Product-" + rand.Next(9999),
                                  Price = rand.Next(1000),
                                  Category = "Category-" + new List<string>() {"RED", "GREEN", "BLUE"}[rand.Next(3)],
                                  Description =
                                      new String(
                                      Enumerable.Range(0, rand.Next(200)).Select(x => (Char) (rand.Next(32, 123))).
                                          ToArray())
                              };
            return product;
        }
    }
}
